package com.itcoon.cloud.framework.utils;

import org.springframework.util.Assert;

public class StringUtil {

    public static String fillPreZero(int number, int expectLength){
        Assert.isTrue(expectLength > 0, "the parameter of 2 must be a number that is greater than 0");
        StringBuilder numberStr = new StringBuilder(String.valueOf(number));
        int diff = expectLength  - numberStr.length();
        if(diff > 0){
            for (int i = 0; i < diff; i++) {
                numberStr.insert(0, "0");
            }
        }
        return numberStr.toString();
    }

    public static boolean isNumeric(String s) {
        if (s != null && !s.trim().isEmpty())
            return s.matches("^[0-9]*$");
        else
            return false;
    }
}
